All Questions
14 questions
4votes
6answers
422views
Search values by priority in a Stream
I have a simple list of results, and I need to return only one value depending on content, for example: ...
3votes
1answer
101views
In Java, replace for loop with condition with lambdas [closed]
I want to replace a for loop with a break/return condition inside with a lambda. I think I have a good replacement, but I want ...
5votes
2answers
161views
Print the three most occurring chars in Java using streams
The three characters that occurs most in a given string should be printed by using streams/lambdas (functional programming). The order of characters that occur equally often should be preserved. My ...
3votes
2answers
437views
Streaming substrings of a string
Given a (long) string src, generate substrings (up to) len characters long on demand by iterating over ...
1vote
3answers
113views
Picking from a list of individuals based on their fitness values
I have this method that takes a list of my individuals (class has public field fitnessValue). I sum all fitnessValue and then ...
7votes
3answers
282views
Sequencing Collector for Either
Using Java 8, I'd like to sequence my eithers using a Collector: Sequencing a stream of eithers means for me: If there's at least one left either inside the stream, I expect the Collector to return ...
3votes
3answers
225views
Stopping an infinite stream with collection state
I took up a somewhat interesting challenge when I answered this question. The task is to collect the first occurrences of different types of animals from an infinite stream until you've caught them ...
11votes
1answer
8kviews
Creating a pipeline operator in Java
I wrote the following as more of an experiment than anything else, but I thought it would be fun to share and maybe get some feedback! Motivation: I started looking at some functional languages and ...
21votes
4answers
18kviews
Filtering out empty Optionals
I want to convert my list of optional strings to a list of strings by getting rid of the empty Optionals. Is there a shorter version for achieving this than the ...
4votes
2answers
210views
ConsumingRouter to consume based on condition
Started as to make a stream splitter to split stream based on condition, but finally found that I did ConsumingRouter, to consume based on condition and while have to provide consumers before using ...
12votes
2answers
722views
Printing removed items using lambdas and streams
I'm struggling to make my lambdas readable. I've seen various approaches. Below are three different examples that all do the same thing. Forgive the example: I suspect there are better actual ...
19votes
1answer
444views
Streaming Collatz
Challenge The recent question The 3n + 1 algorithm for a range inspired me to investigate a Java-8 dependent streaming mechanism for solving the programming challenge: For any two numbers ...
15votes
3answers
114kviews
Compare values of elements in Stream
I'm having fun with Java's Stream library and lambdas. The following code looks for persons within a list that have the same ID (which might indicate that something's wrong with the data) and prints ...
18votes
3answers
27kviews
Effective use of multiple streams
I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code. This code finds the Cartesian product of ...